<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青涩  <3489621943@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2021年03月24日
// +----------------------------------------------------------------------

include("../includes/common.php");
$title='系统设置';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>系统设置</title>
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/materialdesignicons.min.css" rel="stylesheet">
<link href="../assets/css/style.min.css" rel="stylesheet">
</head>
<?php
$scriptpath=str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
$sitepath = substr($scriptpath, 0, strrpos($scriptpath, '/'));
$admin_path = substr($sitepath, strrpos($sitepath, '/'));
$siteurl = (is_https() ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].str_replace($admin_path,'',$sitepath).'/';

$mod=isset($_GET['mod'])?$_GET['mod']:'site';
if($mod=='site_n' && $_POST['do']){
	$admin_user=trim($_POST['admin_user']);
	$admin_pwd=trim($_POST['admin_pwd']);
	$qq_appid=trim($_POST['qq_appid']);
	$qq_appkey=trim($_POST['qq_appkey']);
	if(!$admin_user)showmsg('管理员用户名不能为空',3);
	if(!empty($admin_pwd))$conf['admin_pwd'] = $admin_pwd;
	$conf['admin_user'] = $admin_user;
	$conf['qq_appid'] = $qq_appid;
	$conf['qq_appkey'] = $qq_appkey;

	$data = '<?php'."\r\n".'return ['."\r\n";
	foreach($conf as $key=>$value){
		$data .= '"'.$key.'" => "'.$value.'",'."\r\n";
	}
	$data .= '];';
	if(file_put_contents(SYSTEM_ROOT.'siteconfig.php', $data)){
		showmsg('修改成功！',1);
	}else{
		showmsg('保存失败，请确保有本地写入权限',3);
	}
}elseif($mod=='site'){
?>
<div class="container-fluid p-t-15">
  
  <div class="row">
    
    <div class="col-lg-6">
      <div class="card">
        <header class="card-header"><div class="card-title">系统设置</div></header>
        <div class="card-body">
  <form action="./set.php?mod=site_n" method="post" class="form-horizontal" role="form"><input type="hidden" name="do" value="1"/>
  	<div class="form-group">
	  <label class="col-sm-3 control-label">QQ快捷登录Appid</label>
	  <div class="col-sm-9"><input type="text" name="qq_appid" value="<?php echo $conf['qq_appid']; ?>" class="form-control"/></div>
	</div><br/>
	<div class="form-group">
	  <label class="col-sm-3 control-label">QQ快捷登录Appkey</label>
	  <div class="col-sm-9"><input type="text" name="qq_appkey" value="<?php echo $conf['qq_appkey']; ?>" class="form-control"/><a href="https://connect.qq.com" target="_blank" rel="noreferrer">申请地址</a>，回调地址填写：<?php echo $siteurl.'return.php';?></div>
	</div><br/>
	  	<div class="form-group">
	  <label class="col-sm-3 control-label">管理员用户名</label>
	  <div class="col-sm-9"><input type="text" name="admin_user" value="<?php echo $conf['admin_user']; ?>" class="form-control" required/></div>
	</div><br/>
	<div class="form-group">
	  <label class="col-sm-3 control-label">重置密码</label>
	  <div class="col-sm-9"><input type="text" name="admin_pwd" value="" class="form-control" placeholder="不重置管理员密码请留空"/></div>
	</div><br/>
	<div class="form-group">
	  <div class="col-sm-offset-3 col-sm-9"><input type="submit" name="submit" value="保存" class="btn btn-primary form-control"/><br/>
	 </div>
	</div>
  </form>
</div>
</div>
<?php
}
?>
    </div>
  </div>
    <script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/popper.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/main.min.js"></script>
</body>
</html>